#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "wallyingLib.h"
#include "cJSON.h"


int main(int argc, char *argv[])
{
    printf("Hello World! --- cJSON: %s\r\n", cJSON_Version());


    cJSON *root;
    char *out;

    /*==============================================*/
    root = cJSON_CreateObject();

    cJSON_AddStringToObject(root, "name", "wallying");
    cJSON_AddStringToObject(root, "sex", "male");
    cJSON_AddNumberToObject(root, "age", 99);

    out = cJSON_Print(root);
    printf("%s\r\n", out);

    free(out);
    cJSON_Delete(root);


    /*==============================================*/
    root = cJSON_CreateArray();

    cJSON_AddItemToArray(root, cJSON_CreateString("Hello world"));
    cJSON_AddItemToArray(root, cJSON_CreateNumber(10));

    out = cJSON_Print(root);
    printf("%s\r\n", out);

    free(out);
    cJSON_Delete(root);


    /*==============================================*/


    cJSON *json, *name, *sex, *age;
    char *in = "{\"name\":\"wallying\",\"sex\":\"male\",\"age\":99}";

    json = cJSON_Parse(in);

    name = cJSON_GetObjectItem(json, "name");
    sex = cJSON_GetObjectItem(json, "sex");
    age = cJSON_GetObjectItem(json, "age");

    printf("name:%s, sex:%s, age:%d\n", name->valuestring, sex->valuestring, age->valueint);

    printf("name:%s, sex:%s, age:%d\n", name->valuestring, sex->valuestring, age->valueint);

    cJSON_Delete(json);








    system("pause");
    return 0;
}
